//
//  DYJReadContentFooterTableViewCell.m
//  Piece
//
//  Created by dllo on 16/6/15.
//  Copyright © 2016年 Northeast Dianli University. All rights reserved.
//

#import "DYJReadContentFooterTableViewCell.h"


@implementation DYJReadContentFooterTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //喜欢
        _likeImageView = [[UIImageView alloc] init];
        _likeImageView.image = [UIImage imageNamed:@"like_normal"];
        [self.contentView addSubview:_likeImageView];
        //添加点击方法
        _likeImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapLikeImageView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapLikeImageView)];
        [_likeImageView addGestureRecognizer:tapLikeImageView];
        
        _didLikeImageView = [[UIImageView alloc] init];
        _didLikeImageView.image = [UIImage imageNamed:@"like_selected"];
        [self.contentView addSubview:_didLikeImageView];
        _didLikeImageView.hidden = YES;
        //添加点击方法
        _didLikeImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapDidLikeImageView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapDidLikeImageView)];
        [_didLikeImageView addGestureRecognizer:tapDidLikeImageView];
        
        _likeCountsLabel = [[UILabel alloc] init];
        _likeCountsLabel.font = [UIFont systemFontOfSize:10];
        _likeCountsLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_likeCountsLabel];
        
        //分享
        _shareImageView = [[UIImageView alloc] init];
        _shareImageView.image = [UIImage imageNamed:@"share_image"];
        [self.contentView addSubview:_shareImageView];
        //添加点击方法
        _shareImageView.userInteractionEnabled = YES;
        UITapGestureRecognizer *tapShareImageView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapShareImageView)];
        [_shareImageView addGestureRecognizer:tapShareImageView];
        
        _authorIntroductionLabel = [[UILabel alloc] init];
        _authorIntroductionLabel.textColor = [UIColor grayColor];
        _authorIntroductionLabel.font = [UIFont systemFontOfSize:10];
        [self.contentView addSubview:_authorIntroductionLabel];
        
        if ([self isLike] == YES) {
            _likeImageView.hidden = YES;
            _didLikeImageView.hidden = NO;
        }
        else
        {
            _likeImageView.hidden = NO;
            _didLikeImageView.hidden = YES;
        }
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _likeImageView.frame = CGRectMake(ScreenWidth - 150, 0, 40, 40);
    _didLikeImageView.frame = CGRectMake(ScreenWidth - 150, 0, 40, 40);
    _likeCountsLabel.frame = CGRectMake(self.likeImageView.frame.origin.x + 43, 0, 50, 40);
    _shareImageView.frame = CGRectMake(ScreenWidth - 60, 0, 40, 40);
    _authorIntroductionLabel.frame = CGRectMake(10, 0, ScreenWidth - 160, 40);
}
- (void)didTapLikeImageView
{
    static const CGFloat scaleMultiple = 2.0;
    
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isLike"];
    _likeImageView.hidden = YES;
    _didLikeImageView.hidden = NO;
    [UIView animateWithDuration:0.1 delay:0 usingSpringWithDamping:1.0 initialSpringVelocity:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{
        
        _didLikeImageView.transform = CGAffineTransformMakeScale(scaleMultiple, scaleMultiple);
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
            
            _didLikeImageView.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {
            
        }];
    }];

}
- (void)didTapDidLikeImageView
{
    [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLike"];
    _likeImageView.hidden = NO;
    _didLikeImageView.hidden = YES;
}
- (void)didTapShareImageView
{
    [self.delegate phushShareView];
}
- (BOOL)isLike
{
    NSUserDefaults *isLike = [NSUserDefaults standardUserDefaults];
    BOOL result = [isLike boolForKey:@"isLike"];
    if (result) {
    
        return YES;
    }
    else
    {
        return NO;
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
